package com.zeek.car90s.util;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import com.zeek.car90s.R;

/**
 * Created by Administrator on 2016/4/10.
 */
public class SoundPoolUtils {
    // SoundPool对象
    private static SoundPool soundPool;
    public static SoundPoolUtils soundPoolUtils;
    // 上下文
    static Context mContext;

    /**
     * 初始化
     *
     * @param context
     */
    public static SoundPoolUtils init(Context context) {
        if (soundPoolUtils == null) {
            soundPoolUtils = new SoundPoolUtils();
        }

        if (soundPool == null) {
            // 初始化声音
            mContext = context;
            soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
            soundPool.load(mContext, R.raw.coin, 1);//1-获取金币的声音
            soundPool.load(mContext, R.raw.bg0, 1);// 2-背景音乐
        }

        return soundPoolUtils;
    }

    /**
     * 播放声音
     *
     * @param soundID
     */
    public static void play(int soundID) {
        if(soundPool!=null) {
            soundPool.play(soundID, 1, 1, 0, 0, 1);
        }
    }
}
